<?php

namespace App\Http\Controllers\Api;
use Mrgoon\AliSms\AliSms;
class VerificationCodeController extends Controller
{
    public function store() {

        $phone = request(['phone']);
        $aliSms = new AliSms();
        $code = str_pad(random_int(1,9999),4,0,STR_PAD_LEFT);
        echo $code;
        //$response = $aliSms->sendSms('18512556616', 'SMS_139170015', ['code'=> '123232']);

        $key = 'verificationCode_'.str_random(15);
        $expiredAt = now()->addMinutes(10);
        \Cache::put($key,['phone'=>$phone,'code'=>$code],$expiredAt);
        return $this->response->array([
            'key'=>$key,
            'expired_at'=>$expiredAt->toDateString()
        ])->setStatusCode(201);

    }
}
